home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / cli / WDelta.lha / WDelta / src / sources / dosio.i next >
Encoding:
Text File  |  1999-06-25  |  5.4 KB  |  257 lines

  1.  IFND DOSIO_I
  2. DOSIO_I=1
  3. ;*---------------------------------------------------------------------------
  4. ;  :Author.    Bert Jahn
  5. ;  :Contens.    macros for input/output via dos.library
  6. ;  :EMail.    wepl@kagi.com
  7. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  8. ;  :Version.    $Id: dosio.i 1.3 1999/06/24 23:13:31 jah Exp jah $
  9. ;  :History.    30.12.95 separated from WRip.asm
  10. ;        18.01.96 IFD Label replaced by IFD Symbol
  11. ;             because Barfly optimize problems
  12. ;        20.01.96 _CheckBreak separated from Wrip
  13. ;        21.07.97 _FGetS added
  14. ;        09.11.97 _GetS added
  15. ;             _FlushInput added
  16. ;  :Requires.    -
  17. ;  :Copyright.    This program is free software; you can redistribute it and/or
  18. ;        modify it under the terms of the GNU General Public License
  19. ;        as published by the Free Software Foundation; either version 2
  20. ;        of the License, or (at your option) any later version.
  21. ;        This program is distributed in the hope that it will be useful,
  22. ;        but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. ;        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. ;        GNU General Public License for more details.
  25. ;        You can find the full GNU GPL online at: http://www.gnu.org
  26. ;  :Language.    68000 Assembler
  27. ;  :Translator.    Barfly V1.130
  28. ;---------------------------------------------------------------------------*
  29. *##
  30. *##    dosio.i
  31. *##
  32. *##    _PrintLn    outputs a linefeed
  33. *##    _PrintArgs    outputs formatstring(a0) expanded from argarray(a1)
  34. *##    _PrintInt    outputs a longint (d0)
  35. *##    _Print        outputs a string(a0)
  36. *##    _FlushInput    flushes the input stream
  37. *##    _FlushOutput    flushes the output stream
  38. *##    _CheckBreak    --> true(d0) if ^C was pressed
  39. *##    _FGetS        fh(d1) buffer(d2) buflen(d3) --> buffer(d0)
  40. *##    _GetS        buffer(a0) buflen(d0) --> buffer(d0)
  41.  
  42.     dc.b    "$Id: dosio.i 1.3 1999/06/24 23:13:31 jah Exp jah $"
  43.     EVEN
  44.  
  45.         IFND    STRINGS_I
  46.             INCLUDE    strings.i
  47.         ENDC
  48.  
  49. ;----------------------------------------
  50. ; Zeilenschaltung
  51. ; Übergabe :    -
  52. ; Rückgabe :    -
  53.  
  54. PrintLn        MACRO
  55.     IFND    PRINTLN
  56. PRINTLN = 1
  57. _PrintLn    movem.l    d2/a6,-(a7)
  58.         move.l    #$0a000000,-(a7)    ;stack always LongWord aligned (speed) !
  59.         move.l    a7,d1
  60.         moveq    #0,d2
  61.         move.l    (gl_dosbase,GL),a6
  62.         jsr    (_LVOVPrintf,a6)
  63.         movem.l    (a7)+,d0/d2/a6        ; !!!
  64.         rts
  65.     ENDC
  66.         ENDM
  67.  
  68. ;----------------------------------------
  69. ; Gibt FormatString gebuffert aus
  70. ; Übergabe :    A0 = CPTR FormatString
  71. ;        A1 = STRUCT Array mit Argumenten
  72. ; Rückgabe :    -
  73.  
  74. PrintArgs    MACRO
  75.     IFND    PRINTARGS
  76. PRINTARGS = 1
  77. _PrintArgs    movem.l    d2/a6,-(a7)
  78.         move.l    a0,d1
  79.         move.l    a1,d2
  80.         move.l    (gl_dosbase,GL),a6
  81.         jsr    (_LVOVPrintf,a6)
  82.         movem.l    (a7)+,d2/a6
  83.         rts
  84.     ENDC
  85.         ENDM
  86.  
  87. ;----------------------------------------
  88. ; Gibt LongInt gebuffert aus
  89. ; Übergabe :    D0 = LONG
  90. ; Rückgabe :    -
  91.  
  92. PrintInt    MACRO
  93.     IFND    PRINTINT
  94. PRINTINT = 1
  95. _PrintInt    clr.l    -(a7)
  96.         move.l    #"%ld"<<8+10,-(a7)
  97.         move.l    a7,a0
  98.         move.l    d0,-(a7)
  99.         move.l    a7,a1
  100.         bsr    _PrintArgs
  101.         add.w    #12,a7
  102.         rts
  103.     ENDC
  104.         ENDM
  105.  
  106. ;----------------------------------------
  107. ; Gibt String gebuffert aus
  108. ; Übergabe :    A0 = CPTR String
  109. ; Rückgabe :    -
  110.  
  111. Print        MACRO
  112.     IFND    PRINT
  113. PRINT = 1
  114.         IFND    PRINTARGS
  115.             PrintArgs
  116.         ENDC
  117.  
  118. _Print        sub.l    a1,a1
  119.         bra    _PrintArgs
  120.     ENDC
  121.         ENDM
  122.  
  123. ;----------------------------------------
  124. ; Löschen der Ausgabepuffer
  125. ; Übergabe :    -
  126. ; Rückgabe :    -
  127.  
  128. FlushOutput    MACRO
  129.     IFND    FLUSHOUTPUT
  130. FLUSHOUTPUT = 1
  131. _FlushOutput    move.l    a6,-(a7)
  132.         move.l    (gl_dosbase,GL),a6
  133.         jsr    (_LVOOutput,a6)
  134.         move.l    d0,d1
  135.         beq    .err
  136.         jsr    (_LVOFlush,a6)
  137. .err        move.l    (a7)+,a6
  138.         rts
  139.     ENDC
  140.         ENDM
  141.  
  142. ;----------------------------------------
  143. ; Übergabe :    -
  144. ; Rückgabe :    -
  145.  
  146. FlushInput    MACRO
  147.     IFND    FLUSHINPUT
  148. FLUSHINPUT = 1
  149. _FlushInput    move.l    a6,-(a7)
  150.         move.l    (gl_dosbase,GL),a6
  151.         jsr    (_LVOInput,a6)
  152.         move.l    d0,d1
  153.         beq    .err
  154.         jsr    (_LVOFlush,a6)
  155. .err        move.l    (a7)+,a6
  156.         rts
  157.     ENDC
  158.         ENDM
  159.  
  160. ;----------------------------------------
  161. ; Check break (CTRL-C)
  162. ; Übergabe :    -
  163. ; Rückgabe :    d0 = BOOL break
  164.  
  165. CheckBreak    MACRO
  166.     IFND    CHECKBREAK
  167. CHECKBREAK=1
  168.     IFND    PRINT
  169.         Print
  170.     ENDC
  171. _CheckBreak    move.l    a6,-(a7)
  172.         move.l    #SIGBREAKF_CTRL_C,d1
  173.         move.l    (gl_dosbase,GL),a6
  174.         jsr    (_LVOCheckSignal,a6)
  175.         tst.l    d0
  176.         beq    .end
  177.         lea    (.break),a0
  178.         bsr    _Print
  179.         moveq    #-1,d0
  180. .end        move.l    (a7)+,a6
  181.         rts
  182. .break        dc.b    "*** User Break ***",10,0
  183.     EVEN
  184.     ENDM
  185.  
  186. ;----------------------------------------
  187. ; get line from file
  188. ; remove all LF,CR,SPACE,TAB from the end of line
  189. ; IN :    D1 = BPTR  fh
  190. ;    D2 = APTR  buffer
  191. ;    D3 = ULONG buffer size
  192. ; OUT :    D0 = ULONG buffer or 0 on error/EOF
  193.  
  194. FGetS    MACRO
  195.     IFND    FGETS
  196. FGETS=1
  197.         IFND    STRLEN
  198.             StrLen
  199.         ENDC
  200. _FGetS        movem.l    d3/a6,-(a7)
  201.         subq.l    #1,d3            ;due a bug in V36/V37
  202.         move.l    (gl_dosbase,GL),a6
  203.         jsr    (_LVOFGets,a6)
  204.         move.l    d0,-(a7)
  205.         beq    .end
  206.     ;remove LF,CR,SPACE,TAB from the end
  207.         move.l    (a7),a0
  208.         bsr    _StrLen
  209. .len        tst.l    d0
  210.         beq    .end
  211.         move.l    (a7),a0
  212.         cmp.b    #10,(-1,a0,d0)        ;LF
  213.         beq    .cut
  214.         cmp.b    #13,(-1,a0,d0)        ;CR
  215.         beq    .cut
  216.         cmp.b    #" ",(-1,a0,d0)        ;SPACE
  217.         beq    .cut
  218.         cmp.b    #"    ",(-1,a0,d0)    ;TAB
  219.         bne    .end
  220. .cut        clr.b    (-1,a0,d0)
  221.         subq.l    #1,d0
  222.         bra    .len
  223. .end        movem.l    (a7)+,d0/d3/a6
  224.         rts
  225.     ENDC
  226.         ENDM
  227.  
  228. ;----------------------------------------
  229. ; get line from stdin
  230. ; remove all LF,CR,SPACE,TAB from the end of line
  231. ; IN :    D0 = ULONG buffer size
  232. ;    A0 = APTR  buffer
  233. ; OUT :    D0 = ULONG buffer or 0 on error/EOF
  234.  
  235. GetS    MACRO
  236.     IFND    GETS
  237. GETS=1
  238.         IFND    FGETS
  239.             FGetS
  240.         ENDC
  241. _GetS        movem.l    d2-d3/a6,-(a7)
  242.         move.l    d0,d3            ;buffer size
  243.         move.l    a0,d2            ;buffer
  244.         move.l    (gl_dosbase,GL),a6
  245.         jsr    (_LVOInput,a6)
  246.         move.l    d0,d1            ;fh
  247.         bsr    _FGetS
  248.         movem.l    (a7)+,_MOVEMREGS
  249.         rts
  250.     ENDC
  251.         ENDM
  252.  
  253. ;----------------------------------------
  254.     
  255.  ENDC
  256.  
  257.